home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / Canvas.java < prev    next >
Text File  |  1998-09-22  |  3KB  |  95 lines

  1. /*
  2.  * @(#)Canvas.java    1.18 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package java.awt;
  15.  
  16. import java.awt.peer.CanvasPeer;
  17.  
  18. /**
  19.  * A <code>Canvas</code> component represents a blank rectangular 
  20.  * area of the screen onto which the application can draw or from 
  21.  * which the application can trap input events from the user. 
  22.  * <p>
  23.  * An application must subclass the <code>Canvas</code> class in 
  24.  * order to get useful functionality such as creating a custom 
  25.  * component. The <code>paint</code> method must be overridden 
  26.  * in order to perform custom graphics on the canvas.
  27.  *
  28.  * @version     1.18 07/01/98
  29.  * @author     Sami Shaio
  30.  * @since       JDK1.0
  31.  */
  32. public class Canvas extends Component {
  33.  
  34.     private static final String base = "canvas";
  35.     private static int nameCounter = 0;
  36.  
  37.     /*
  38.      * JDK 1.1 serialVersionUID 
  39.      */
  40.      private static final long serialVersionUID = -2284879212465893870L;
  41.  
  42.     /** 
  43.      * Constructs a new Canvas.
  44.      */
  45.     public Canvas() {
  46.     }
  47.  
  48.     /**
  49.      * Construct a name for this component.  Called by getName() when the
  50.      * name is null.
  51.      */
  52.     String constructComponentName() {
  53.         return base + nameCounter++;
  54.     }
  55.  
  56.     /**
  57.      * Creates the peer of the canvas.  This peer allows you to change the 
  58.      * user interface of the canvas without changing its functionality.
  59.      * @see     java.awt.Toolkit#createCanvas(java.awt.Canvas)
  60.      * @see     java.awt.Component#getToolkit()
  61.      * @since   JDK1.0
  62.      */
  63.     public void addNotify() {
  64.         synchronized (getTreeLock()) {
  65.         if (peer == null)
  66.             peer = getToolkit().createCanvas(this);
  67.  
  68.         super.addNotify();
  69.         }
  70.     }
  71.  
  72.     /**
  73.      * This method is called to repaint this canvas. Most applications 
  74.      * that subclass <code>Canvas</code> should override this method in 
  75.      * order to perform some useful operation. 
  76.      * <p>
  77.      * The <code>paint</code> method provided by <code>Canvas</code> 
  78.      * redraws this canvas's rectangle in the background color. 
  79.      * <p>
  80.      * The graphics context's origin (0, 0) is the top-left corner 
  81.      * of this canvas. Its clipping region is the area of the context. 
  82.      * @param      g   the graphics context.
  83.      * @see        java.awt.Graphics
  84.      * @since      JDK1.0
  85.      */
  86.     public void paint(Graphics g) {
  87.     g.setColor(getBackground());
  88.     g.fillRect(0, 0, width, height);
  89.     }
  90.  
  91.     boolean postsOldMouseEvents() {
  92.         return true;
  93.     }
  94. }
  95.